﻿using System.Linq;
using UniMana.Utils.Controls;
using UniMana.Data;
using System;
namespace UniMana.Data
{
    public class Training_Session_Subject_Class_RoomInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();
        public void Save()
        {
            this.m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }
        #endregion
        #region [Properties - Thuộc tính]
        public Training_Session_Subject_Class_Room Properties
        {
            get { return m_bds.Current as Training_Session_Subject_Class_Room; }
        }
        #endregion
        public Training_Session_Subject_Class_RoomInfo(
               int schoolYearKey = 0,
               int termKey = 0,
               int subject_ClassKey = 0,
               int session = 0,
               int weekDay = 0,
               DateTime RegistTime = new DateTime())
        {
            var IQuery =
                m_data.m_DCSave.Training_Session_Subject_Class_Rooms.Where(
                        tb => tb.Catalogue_SchoolYearKey == schoolYearKey &&
                        tb.Catalogue_TermKey == termKey &&
                        tb.Training_Subject_ClassKey == subject_ClassKey &&
                        tb.Training_SessionKey == session &&
                        tb.Training_WeekDayKey == weekDay &&
                        tb.RegistTime == RegistTime);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Training_Session_Subject_Class_Room();
                m_bds.Add(Row);
            }
        }

        #region [An]
        /// <summary>
        /// Lấy dữ liệu với buổi học, mã lớp học, ngày đăng ký
        /// </summary>
        /// <param name="m_iTraining_SessionKey"></param>
        /// <param name="m_iTraining_Subject_ClassKey"></param>
        /// <param name="m_dRegistTime"></param>
        public Training_Session_Subject_Class_RoomInfo(int m_iTraining_SessionKey,
            int m_iTraining_Subject_ClassKey,
            DateTime m_dRegistTime)
        {
            var IQuery = m_data.m_DCSave.Training_Session_Subject_Class_Rooms.Where(tb => tb.Training_SessionKey == m_iTraining_SessionKey && tb.Training_Subject_ClassKey == m_iTraining_Subject_ClassKey && tb.RegistTime == m_dRegistTime);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Training_Session_Subject_Class_Room();
                m_bds.Add(Row);
            }
        }

        /// <summary>
        /// Lấy dữ liệu với giảng viên, lớp, ngày, buổi
        /// </summary>
        /// <param name="m_strPersonnel"></param>
        /// <param name="m_iClassKey"></param>
        /// <param name="m_dRegist"></param>
        /// <param name="m_iSession"></param>

        public Training_Session_Subject_Class_RoomInfo(string m_strPersonnel,
            int m_iClassKey,
            DateTime m_dRegist,
            int m_iSession)
        {
            var IQuery = m_data.m_DCSave.Training_Session_Subject_Class_Rooms.Where(tb => tb.Personnel_PersonnelKey.ToString() == m_strPersonnel && tb.Training_Subject_ClassKey == m_iClassKey && tb.RegistTime == m_dRegist && tb.Training_SessionKey == m_iSession);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Training_Session_Subject_Class_Room();
                m_bds.Add(Row);
            }
        }

        #endregion
    }
}
